<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/* Start of file accounts.php */
/* Location: ./cashflow/models/accounts.php */
class Accounts extends CI_Model {
    
	function __construct(){
        parent::__construct(); /** Call the Model constructor */
    }
    
    function getAccountData(){
        $this->db->order_by('NoRekening','ASC');
		$Q=$this->db->get('rekening');
		if ($Q->num_rows() > 0):
			foreach ($Q->result_array() as $row):
				$data[$row['NoRekening']] = $row['NoRekening'] .'-'. $row['Branch'];
			endforeach;
		endif;
        $Q->free_result();
		return $data;   
	}
    
    function getAccount($no=''){
        if($no)
            $this->db->where('NoRekening',$no);
        $Q = $this->db->get('rekening',1);
        return $Q->row_array();    
    }
    
    function getAllAccount(){
        $this->db->order_by('MataUang','DESC');
        $Q=$this->db->get('rekening');
        return $Q->result_array(); 
    }
    
    function getAccountSaldo($no,$month,$year,$balance = 'no'){
        $this->db->select('Saldo');
        $this->db->where('NoRekening',$no);
        if($balance=='yes'):
            if(trim($month)=='01'):
                $month = '12';
                $year = $year-1;
            else:
                $month = $month - 1;
                $year = $year;    
            endif;
        endif;
        $this->db->where('Bulan',$month);
        $this->db->where('Tahun',$year);        
        $Q=$this->db->get('saldo');
        return $Q->row_array();
        
    }
    
    function getConvertSaldo($curr='USD',$month='',$year=''){
        $this->db->select('Value',FALSE);
        $this->db->where('Currency',$curr);
        $this->db->where('Tanggal',"(SELECT MAX(TANGGAL) FROM kurs_pajak WHERE Currency='".$curr."' AND MONTH(Tanggal)='".$month."' AND YEAR(Tanggal)='".$year."' LIMIT 1)",FALSE);
        $Q=$this->db->get('kurs_pajak',1); 
        return $Q->row_array();
    }
    
    
}    